<?php
	
	session_start();
	require 'include/configDB.php';
	 if (! isset($_SESSION['role']) || ($_SESSION['role'] != "Admin") && ($_SESSION['role'] != "Staff Tata Usaha")) {
  		header('Location: login.php');
	}
	
	if (isset($_POST['jurusan'])) {
		$tingkat = $_POST['tingkat'];
		$id_jurusan = $_POST['jurusan'];
		$no_kelas = $_POST['no_kelas'];


		$kelas_query = mysql_query("SELECT * FROM kelas WHERE tingkat='$tingkat' AND id_jurusan='$id_jurusan' AND nomor='$no_kelas'");
		$kelas= mysql_fetch_assoc($kelas_query);
		$id_kelas = $kelas['id'];

		$Jadwal_pelajaran = mysql_query("SELECT * FROM Jadwal_pelajaran WHERE id_kelas=".$id_kelas);
	} else {
		$Jadwal_pelajaran = mysql_query("SELECT * FROM Jadwal_pelajaran");
	}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Laporan Jadwal Pelajaran</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="clockp.js"></script>
<script type="text/javascript" src="clockh.js"></script> 
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="ddaccordion.js"></script>
<script type="text/javascript">
ddaccordion.init({
	headerclass: "submenuheader", //Shared CSS class name of headers group
	contentclass: "submenu", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["suffix", "<img src='images/plus.gif' class='statusicon' />", "<img src='images/minus.gif' class='statusicon' />"], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})
</script>

<script type="text/javascript" src="jconfirmaction.jquery.js"></script>
<script type="text/javascript">
	
	$(document).ready(function() {
		$('.ask').jConfirmAction();
	});
	
</script>

<script language="javascript" type="text/javascript" src="niceforms.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="niceforms-default.css" />
<style>
	<?php include 'include_style.php'; ?>
</style>
</head>
<body>
<div id="main_container">

	<?php include 'header.php'; ?>
    
    <div class="main_content">
                
                    
    <div class="center_content">
		
    
	
    <div class="left_content">
    
    		<?php include 'left_content.php'; ?>
    		<?php include 'calendar.php' ; ?>

    </div>  
    
    <div class="right_content">
		<h2>Jadwal Pelajaran</h2>
		<form action="laporan_jadwal_pelajaran.php" method="post" >  
		<table>
			<?php
				$query = mysql_query("SELECT * FROM tahun_ajaran");
			?>
			<tr>
				<td>
					<label>Tahun Ajaran
					</label>
				</td>
				<td>
					:
				</td>
				<td>
					<select name = "tahun_ajaran">
						<option value="NULL">---------Pilih----------</option>
						<?php

						while ($tahun_ajaran_data = mysql_fetch_assoc($query)) {
						?>
						<option value="<?php echo $tahun_ajaran_data['id'];?>" <?php if (isset($_POST['tahun_ajaran']) && ($_POST['tahun_ajaran'] == $tahun_ajaran_data['id'])) echo "selected";?>>
							<?php echo $tahun_ajaran_data['tahun_ajaran'];?>
						</option>
						<?php } ?>	
					</select>
				</td>
			</tr>
			<tr>
				<td>
					<label>Kelas
					</label>
				</td>
				<td>
					:
				</td>
				<td>
					<select name="tingkat">
						<option value="NULL">---------Pilih----------</option>
						<option value="10" <?php if (isset($_POST['tingkat']) && ($_POST['tingkat'] == '10')) echo "selected";?>>10</option>
						<option value="11" <?php if (isset($_POST['tingkat']) && ($_POST['tingkat'] == '11')) echo "selected";?>>11</option>inou:inp
						<option value="12" <?php if (isset($_POST['tingkat']) && ($_POST['tingkat'] == '12')) echo "selected";?>>12</option>	  	
					</select>
				</td>
				<td>
					<select name="jurusan">
						<option value="NULL">---------Pilih----------</option>
						<?php
						$query = mysql_query("SELECT * FROM jurusan");

						while ($data = mysql_fetch_assoc($query)) {
						?>
						<option value="<?php echo $data['id'];?>" <?php if (isset($_POST['jurusan']) && ($_POST['jurusan'] == $data['id'])) echo "selected";?>>
							<?php echo $data['nama'];?>
						</option>
						<?php } ?>
					</select>
				</td>
				<td>
					<select name="no_kelas">
						<option value="NULL">---------Pilih----------</option>
						<option value="1" <?php if (isset($_POST['no_kelas']) && ($_POST['no_kelas'] == '1')) echo "selected";?>>1</option>
						<option value="2" <?php if (isset($_POST['no_kelas']) && ($_POST['no_kelas'] == '2')) echo "selected";?>>2</option>
						<option value="3"  <?php if (isset($_POST['no_kelas']) && ($_POST['no_kelas'] == '3')) echo "selected";?>>3</option>	
					    <option value="4"  <?php if (isset($_POST['no_kelas']) && ($_POST['no_kelas'] == '4')) echo "selected";?>>4</option>
					     <option value="5"  <?php if (isset($_POST['no_kelas']) && ($_POST['no_kelas'] == '5')) echo "selected";?>>5</option>
					</select>
				</td>
			</tr>
			<tr>
				<td><input type="submit" name="submit" class="menuitem_red" value="Lihat"/></td>
			</tr>
		</table>  
		<br>
		
		       
		<table id="rounded-corner" summary="2007 Major IT Companies' Profit">
			<thead>
				<tr>
					<th scope="col" class="rounded">No</th>
					<th scope="col" class="rounded">Hari</th>
					<th scope="col" class="rounded">Nama Mata Pelajaran</th>
					<th scope="col" class="rounded">Nama Guru</th>
					<th scope="col" class="rounded">Waktu Mulai</th>
					<th scope="col" class="rounded">Waktu Selesai</th>		
					<th scope="col" class="rounded">Edit</th>
					<th scope="col" class="rounded-q4">Delete</th>
				</tr>
			</thead>
				
			<tbody>
				<?php
					$i=1;
					while ($jadwal_pelajaran_data = mysql_fetch_assoc($Jadwal_pelajaran)) 
					{
						$id_penugasan = $jadwal_pelajaran_data['id_penugasan'];
						$penugasan = mysql_query("SELECT * FROM penugasan_guru WHERE id='$id_penugasan'");
						$penugasan_data = mysql_fetch_assoc($penugasan);
						$id_matpel = $penugasan_data['id_matpel'];
						$matpel = mysql_query("SELECT * FROM mata_pelajaran WHERE id='$id_matpel' ");
						$matpel_data = mysql_fetch_assoc($matpel);
						$id_guru = $penugasan_data['NIK'];
						$guru = mysql_query("SELECT * FROM guru WHERE NIK='$id_guru'");
						$guru_data = mysql_fetch_assoc($guru);

						echo 
						'
						<tr>
							<td>'.$i.'</td>
							<td>'.$jadwal_pelajaran_data['hari'].'</td>
							<td>'.$matpel_data['nama'].'</td>
							<td>'.$guru_data['nama'].'</td>
							<td>'.$jadwal_pelajaran_data['waktu_mulai'].'</td>
							<td>'.$jadwal_pelajaran_data['waktu_selesai'].'</td>
							<td><a href="edit_jadwal_pelajaran.php?id='.$jadwal_pelajaran_data['id'].'"><img src="images/user_edit.png" alt="" title="" border="0" /></a></td>
							<td><a href="include/delete_jadwal_pelajaran.php?id='.$jadwal_pelajaran_data['id'].'" class="ask"><img src="images/trash.png" alt="" title="" border="0" /></a></td>
						</tr>	
						';
						$i++;
					
					}
				?>
			</tbody>
		</table>
		</form>
		<form action="input_jadwal_pelajaran.php" method="post" >
			<?php if (isset($_POST['jurusan'])) {
				?>

				<input type="hidden" name="tahun_ajaran" value="<?php echo $_POST['tahun_ajaran'];?>" />
				<input type="hidden" name="tingkat" value="<?php echo $_POST['tingkat'];?>" />
				<input type="hidden" name="jurusan" value="<?php echo $_POST['jurusan'];?>" />
				<input type="hidden" name="no_kelas" value="<?php echo $_POST['no_kelas'];?>" />

				<table>
					<tbody>
						<tr>
							<td><input type="submit" name="submit" class ="menuitem_red"value="Tambah"/></td>
						</tr>
					</tbody>
				</table>
				<?php
			}?>

			
		</form>
		
    </div><!-- end of right content-->
            
                    
  </div>   <!--end of center content -->               
                    
                    
    
    
    <div class="clear"></div>
    </div> <!--end of main content-->
	
    
    <div class="footer">
        	<?php include 'footer.php'; ?>

    	
    </div>

</div>		
</body>
</html>